<?php

/**
 * Class TaxonomyViewAction
 */
class TaxonomyDeleteAction extends CAction
{
	public $bundle;

	public function run($id)
	{
		if (Yii::app()->getRequest()->getIsPostRequest()) {
			$result = $this->loadModel($id)->delete();

			if (!isset($_GET['ajax'])) {
				$result && Yii::app()->getUser()->setFlash('success', '分类删除成功');
				$this->getController()->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
			}
		} else {
			throw new CHttpException(405, '无效的请求，请重试');
		}
	}

	public function loadModel($id)
	{
		if ($this->bundle) {
			$condition = 'bundle=:bundle';
			$params = array(':bundle' => $this->bundle);
		} else {
			$condition = '';
			$params = array();
		}
		if (!$model = Taxonomy::model()->findByPk($id, $condition, $params)) {
			throw new CHttpException(404, '页面没有找到');
		}
		return $model;
	}
} 